package com.feri.rbacsys.controller;

import com.feri.rbacsys.entity.Category;
import com.feri.rbacsys.service.intf.CategoryService;
import com.feri.rbacsys.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * (Category)表控制层
 *
 * @author makejava
 * @since 2023-03-27 21:00:18
 */
@RestController
@RequestMapping("/api/category/")
@Api(tags = "品类相关接口")
public class CategoryController {
    /**
     * 服务对象
     */
    @Resource
    private CategoryService service;

    /**
     * 新增数据
     *
     * @param category 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    public R insert(@RequestBody Category category) {
        if(service.save(category)){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 修改数据
     *
     * @param category 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    public R update(@RequestBody Category category) {
        if(service.updateById(category)){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 删除 单个数据*/
    @ApiOperation(value = "实现删除")
    @DeleteMapping("del.do")
    public R del(int id){
        if(service.removeById(id)){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 查询*/
    @ApiOperation(value = "实现查询")
    @DeleteMapping("all")
    public R selectAll(){
        return R.ok(service.list());
    }


}

